package com.ymttest.business.service;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.math.RandomUtils;
import org.apache.http.client.ClientProtocolException;

import com.ymatou.app.api.parameter.RegisterByMobileBean;
import com.ymatou.app.api.parameter.SendRegisterValidateCodeBean;
import com.ymatou.app.api.service.RegisterByMobileCall;
import com.ymatou.app.api.service.SendRegisterValidateCodeCall;
import com.ymatou.query.trading.api.parameter.GetUserAccountInfoBean;
import com.ymatou.query.trading.api.service.GetUserAccountInfoCall;
import com.ymatou.userregister.parameter.YmatouUserRegBean;
import com.ymatou.userregister.service.YmatouUserRegCall;
import com.ymatou.userservice.parameter.AliUserRequestDtoBean;
import com.ymatou.userservice.parameter.CheckMobileIsBindThirdPartyUserDtoBean;
import com.ymatou.userservice.parameter.CheckMobileIsBindYmatouUserDtoBean;
import com.ymatou.userservice.parameter.LoginBillsRequestDtoBean;
import com.ymatou.userservice.parameter.OnlinestatusOpBean;
import com.ymatou.userservice.parameter.PasswordRequestDtoBean;
import com.ymatou.userservice.parameter.PasswordResetRequestDtoBean;
import com.ymatou.userservice.parameter.SetNickNameDtoBean;
import com.ymatou.userservice.parameter.SetThirdPartyUserLoginBillsDtoBean;
import com.ymatou.userservice.parameter.SinaWeiBoUserRequestDtoBean;
import com.ymatou.userservice.parameter.UnBindThirdPartyAccountDtoBean;
import com.ymatou.userservice.parameter.UserLogoRequestDtoBean;
import com.ymatou.userservice.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.userservice.parameter.WeiXinUserRequestDtoBean;
import com.ymatou.userservice.service.AliUserRequestDtoCall;
import com.ymatou.userservice.service.CheckMobileIsBindThirdPartyUserDtoCall;
import com.ymatou.userservice.service.CheckMobileIsBindYmatouUserDtoCall;
import com.ymatou.userservice.service.LoginBillsRequestDtoCall;
import com.ymatou.userservice.service.OnlinestatusOpCall;
import com.ymatou.userservice.service.PasswordRequestDtoCall;
import com.ymatou.userservice.service.PasswordResetRequestDtoCall;
import com.ymatou.userservice.service.SetNickNameDtoCall;
import com.ymatou.userservice.service.SetThirdPartyUserLoginBillsDtoCall;
import com.ymatou.userservice.service.SinaWeiBoUserRequestDtoCall;
import com.ymatou.userservice.service.UnBindThirdPartyAccountDtoCall;
import com.ymatou.userservice.service.UserLogoRequestDtoCall;
import com.ymatou.userservice.service.UserRegisterInfoRequestDtoCall;
import com.ymatou.userservice.service.WeiXinUserRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymttest.common.enums.ChannelSourceEnum;
import com.ymttest.common.enums.UserTerminalSourceEnum;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.database.sqlwapper.YmtUsersWapper;
import com.ymttest.database.sqlwapper.YmtValidationCodeWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;
import com.ymttest.utils.constant.AppTypeChannel;
import com.ymttest.utils.constant.ECode;

/************************************************************************************
 * @File name :UserCallService.java
 * @Author : zhouyi
 * @Date : 2016年7月26日
 * @Copyright : 洋码头
 * @deprecated 这个站点已经废弃 java化新站点替代
 ************************************************************************************/
public class UserCallService {

	/**
	 * 随机生成手机号，发短信
	 * 
	 * @return
	 */
	public static String sendRegisterValidateCode() {
		SendRegisterValidateCodeBean srvcbean = new SendRegisterValidateCodeBean();
		SendRegisterValidateCodeCall srvccall = new SendRegisterValidateCodeCall();
		String Phone = null;
		try {
			for (int i = 0; i < 3; i++) {
				Phone = TestDataManager.getCommPhoneNum();
				srvcbean.setPhone(Phone);
				srvccall.setData(false, srvcbean);
				srvccall.callService();
				Logger.debug(Phone + " SendRegisterValidateCode:"
						+ srvccall.getReturnData());
				String msg = srvccall.getMsg();
				Logger.debug("第" + i + "次发送验证码:" + msg);
				if (msg.equals("")) {
					return Phone;
				}
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
		return Phone;
	}

	/**
	 * 随机生成手机号注册账户,登录密码默认123456
	 * 
	 * @return {Phone=13917923476, AccessToken=, UserId=3795414}
	 */
	@SuppressWarnings("rawtypes")
	@Deprecated
	public static Map<String, Comparable> oldregisterByMobile() {
		Map<String, Comparable> userMap = new HashMap<String, Comparable>();
		RegisterByMobileBean rgbmbean = new RegisterByMobileBean();
		RegisterByMobileCall rgbmcall = new RegisterByMobileCall();
		String phone = null;
		try {
			phone = sendRegisterValidateCode();// 发送验证码
			// 查询验证码
			String code = new YmtValidationCodeWapper().getValidateCode(phone);
			rgbmbean.setCode(code);
			rgbmbean.setPhone(phone);
			String userName = "test" + TestDataManager.randomStr(5)
					+ RandomUtils.nextInt(5);
			rgbmbean.setUserName(userName);
			rgbmbean.setPassword("123456a");
			rgbmbean.setUserLogo("userlogo");
			rgbmcall.setData(false, rgbmbean);
			rgbmcall.callService();
			Logger.debug("通过手机注册用户 call:" + rgbmcall.getEntityString());
			Logger.debug("通过手机注册用户 response:" + rgbmcall.getReturnData());
			userMap.put("username", userName);
			userMap.put("phone", phone);
			userMap.put("accesstoken", rgbmcall.getAccessToken());
			userMap.put("userid", rgbmcall.getUserId());
			// 强制更新交易密码为 abc123
			new YmtUsersWapper().updateTradingPwdByUid(rgbmcall.getUserId());
			// 建立用户账户信息 新资金系统上线后，无效
			// getUserAccountInfo(rgbmcall.getUserId());
			// 初始账号可用余额为100W
			new DefaultWapper().updateAccountInfo(new BigDecimal(1000000),
					rgbmcall.getUserId());
		} catch (Exception e) {
			Logger.fail(e);
		}
		return userMap;
	}
	public static UserRegisterInfoRequestDtoBean initUserRegInfo() {
		UserRegisterInfoRequestDtoBean rgbmbean = new UserRegisterInfoRequestDtoBean();
		String loginId = "autotest_" + TestDataManager.randomStr(10);
		String loginMail = loginId + "@ymatou.com";
		String loginMobile = TestDataManager.getPhoneNum();
		String pas = "123456a";
		int registerType = 0;
		Boolean isAgreeContract = true;
		int regSource = 0;
		int visitLan = 0;
		ChannelSourceEnum channelSource = ChannelSourceEnum.Other;
		UserTerminalSourceEnum terminalSource = UserTerminalSourceEnum.Android;
		String clientIp = TestDataManager.getRandomIp();
		Long tokenTimeOut = (long) 300000;

		rgbmbean.setLoginId(loginId);
		rgbmbean.setLoginMail(loginMail);
		rgbmbean.setLoginMobile(loginMobile);
		rgbmbean.setPas(pas);
		rgbmbean.setRegisterType(registerType);
		rgbmbean.setIsAgreeContract(isAgreeContract);
		rgbmbean.setRegSource(regSource);
		rgbmbean.setVisitLan(visitLan);
		rgbmbean.setChannelSource(channelSource);
		rgbmbean.setTerminalSource(terminalSource);
		rgbmbean.setClientIp(clientIp);
		rgbmbean.setTokenTimeOut(tokenTimeOut);
		return rgbmbean;
	}
	public static Map<String, Comparable> registerByMobile(
			UserRegisterInfoRequestDtoBean rgbmbean) throws Exception {

		Map<String, Comparable> userMap = new HashMap<String, Comparable>();
		UserRegisterInfoRequestDtoCall rgbmcall = new UserRegisterInfoRequestDtoCall();
		rgbmcall.setData(false, rgbmbean);

		rgbmcall.callService();
		int uid = rgbmcall.getUserid();
		userMap.put("ip", rgbmbean.getClientIp());
		userMap.put("username", rgbmbean.getLoginId());
		userMap.put("phone", rgbmbean.getLoginMobile());
		userMap.put("accesstoken", rgbmcall.getAccessToken());
		userMap.put("userid", uid);
		userMap.put("email", rgbmbean.getLoginMail());
		userMap.put("channelSource", rgbmbean.getChannelSource());
		userMap.put("terminalSource", rgbmbean.getTerminalSource());
		// 强制更新交易密码为 abc123
		new YmtUsersWapper().updateTradingPwdByUid(uid);
		// 建立用户账户信息
		// getUserAccountInfo(uid);
		// 初始账号可用余额为100W
		// new DefaultWapper().updateAccountInfo(new BigDecimal(1000000),
		// uid);
		// 添加地址
		int aid = YmtCallService.addAddress(rgbmcall.getAccessToken(), uid);
		userMap.put("addressid", aid);
		String accountid1 = AccountCallService.getAccountId(uid);
		AccountCallService.resetAccount(accountid1, new BigDecimal(99999999),
				new BigDecimal(0));
		userMap.put("accountid", accountid1);
		return userMap;
	}
	/**
	 * @return
	{accountid=01010020365748, phone=13532396526, ip=188.93.115.200, accesstoken=494679E946403CAD1ECF90B13D86CDA6CA2B8D10A3ADAEE504007200346808A3348C90B0B4E71979477261893F327DDB959B6EC42A442795, terminalSource=Android, userid=20365748, email=autotest_7TR2SwAraM@ymatou.com, username=autotest_7TR2SwAraM, channelSource=Other, addressid=861613}
	 */
	@SuppressWarnings("rawtypes")
	public static Map<String, Comparable> registerByMobile() {
		Map<String, Comparable> userMap = new HashMap<String, Comparable>();
		UserRegisterInfoRequestDtoBean rgbmbean = new UserRegisterInfoRequestDtoBean();
		UserRegisterInfoRequestDtoCall rgbmcall = new UserRegisterInfoRequestDtoCall();
		try {
			Logger.comment("注册一个新用户");
			String loginId = "autotest_" + TestDataManager.randomStr(10);
			String loginMail = loginId + "@ymatou.com";
			String loginMobile = TestDataManager.getPhoneNum();
			String pas = "123456a";
			int registerType = 0;
			Boolean isAgreeContract = true;
			int regSource = 0;
			int visitLan = 0;
			ChannelSourceEnum channelSource = ChannelSourceEnum.Other;
			UserTerminalSourceEnum terminalSource = UserTerminalSourceEnum.Android;
			String clientIp = TestDataManager.getRandomIp();
			Long tokenTimeOut = (long) 300000;

			rgbmbean.setLoginId(loginId);
			rgbmbean.setLoginMail(loginMail);
			rgbmbean.setLoginMobile(loginMobile);
			rgbmbean.setPas(pas);
			rgbmbean.setRegisterType(registerType);
			rgbmbean.setIsAgreeContract(isAgreeContract);
			rgbmbean.setRegSource(regSource);
			rgbmbean.setVisitLan(visitLan);
			rgbmbean.setChannelSource(channelSource);
			rgbmbean.setTerminalSource(terminalSource);
			rgbmbean.setClientIp(clientIp);
			rgbmbean.setTokenTimeOut(tokenTimeOut);
			rgbmcall.setData(false, rgbmbean);

			rgbmcall.callService();

			if (rgbmcall.getString("ResponseCode").equals("400")) {
				loginId = "autotest_" + TestDataManager.randomStr(10);
				loginMail = loginId + "@ymatou.com";
				loginMobile = TestDataManager.getPhoneNum();
				rgbmcall = new UserRegisterInfoRequestDtoCall();
				rgbmcall.callService();
			}
			if (rgbmcall.getString("ErrorCode") != null
					&& rgbmcall.getString("ErrorCode").equals("100005")) {
				loginMobile = TestDataManager.getPhoneNum();
				rgbmcall = new UserRegisterInfoRequestDtoCall();
				rgbmcall.callService();
			}
			int uid = rgbmcall.getUserid();
			userMap.put("ip", clientIp);
			userMap.put("username", loginId);
			userMap.put("phone", loginMobile);
			userMap.put("accesstoken", rgbmcall.getAccessToken());
			userMap.put("userid", uid);
			userMap.put("email", loginMail);
			userMap.put("channelSource", channelSource);
			userMap.put("terminalSource", terminalSource);
			// 强制更新交易密码为 abc123
			//new YmtUsersWapper().updateTradingPwdByUid(uid);
			new UserCallService().modifyTradingPassword(uid, "abc123");
			// 添加地址
			JUserCallService.AddressRequestDtoCall(JUserCallService
					.initAddressBean(uid));

			/*	int aid = YmtCallService.addAddress(rgbmcall.getAccessToken(), uid);
				userMap.put("addressid", aid);*/
			String accountid1 = AccountCallService.getAccountId(uid);
			AccountCallService.resetAccount(accountid1,
					new BigDecimal(99999999), new BigDecimal(0));
			userMap.put("accountid", accountid1);
			// TestDataManager.appendFileToLine("data", userMap.toString());
		} catch (Exception e) {
			Logger.fail(e);
		}
		return userMap;
	}
	/**
	 * 通过userregister接口注册用户，可以选择是否填写邮箱和手机号
	 * {loginId=RegTest_3483385909, phone=13702910772, ip=222.146.115.21, userId=20362861, email=v4vS9j8fp5F@qq.com, token=2787CF33CD60BCB73F594DDDF8E4B3D5B95BABA371C1A18A8A7EC46009AB1EFEBA8E8C6FF1BF36A2FC03326F166D51597DA403E26EF3B43D}
	 * @param email
	 * @param phone
	 * @throws IOException
	 * @throws ClientProtocolException
	 */
	public static Map registerUser(String email, String phone, String ip)
			throws Exception {
		if (phone == null) {
			phone = TestDataManager.getPhoneNum();
		}
		String loginId = "RegTest_" + TestDataManager.getRandomNum(10);
		YmatouUserRegBean regBean = new YmatouUserRegBean();
		YmatouUserRegCall regCall = new YmatouUserRegCall();
		if (ip == null) {
			regBean.setClientIp(null);
		} else if (ip.length() < 7) {
			regBean.setClientIp("1.1.1.1");
		} else {
			regBean.setClientIp(ip);
		}
		regBean.setIsAgreeContract(true);
		regBean.setLoginId(loginId);
		if (phone != null)
			regBean.setLoginMobile(phone);
		if (email != null)
			regBean.setLoginMail(email);
		regBean.setPas("123456a");
		regBean.setRegisterType(0);
		regBean.setRegSource(1);
		regBean.setTokenTimeOut(2000L);
		regBean.setTerminalSource(UserTerminalSourceEnum.Ios);
		regBean.setVisitLan(1);
		regBean.setDeviceId(TestDataManager.getRandomUUID().toString());
		regCall.setData(false, regBean);
		regCall.callService();
		if (regCall.getUserId() == 0) {
			return null;
		}
		Map user = new HashMap<String, Object>();
		user.put("phone", phone);
		user.put("loginId", loginId);
		user.put("email", email);
		user.put("userId", regCall.getUserId());
		user.put("token", regCall.getToken());
		user.put("ip", ip);
		user.put("did", regBean.getDeviceId());
		AccountCallService acc = new AccountCallService();
		String accountinfoid = acc.getAccountId(regCall.getUserId());
		if (accountinfoid != null && accountinfoid.length() > 0)
			new AccountCallService().resetAccount(accountinfoid,
					new BigDecimal(1000), new BigDecimal(1000));
		return user;
	}
	/**
	 * {loginId=RegTest_3153947002, phone=13063766124, ip=1.1.10.3, userId=20362885, email=pjvUu81J@qq.com, did=5200692f-ca46-4bbb-9114-f276684d8e66, token=B681808E97DE22200AD06D8663BF329A4678810ED0F676DEFB9CC13F92B345EDC34BC0CADFE210F7DE487D07014CB61D13F75D173A5B7C72}
	 * @param email
	 * @param phone
	 * @param ip
	 * @return
	 * @throws Exception
	 */
	public static Map regForUserService(String email, String phone, String ip)
			throws Exception {
		if (phone == null) {
			phone = TestDataManager.getPhoneNum();
		}
		String loginId = "RegTest_" + TestDataManager.getRandomNum(10);
		UserRegisterInfoRequestDtoBean regBean = new UserRegisterInfoRequestDtoBean();
		UserRegisterInfoRequestDtoCall regCall = new UserRegisterInfoRequestDtoCall();
		if (ip == null) {
			regBean.setClientIp(null);
		} else if (ip.length() < 7) {
			regBean.setClientIp("1.1.1.1");
		} else {
			regBean.setClientIp(ip);
		}
		regBean.setIsAgreeContract(true);
		regBean.setLoginId(loginId);
		if (phone != null)
			regBean.setLoginMobile(phone);
		if (email != null)
			regBean.setLoginMail(email);
		regBean.setPas("123456a");
		regBean.setRegisterType(0);
		regBean.setRegSource(1);
		regBean.setTokenTimeOut(2000L);
		regBean.setTerminalSource(UserTerminalSourceEnum.Ios);
		regBean.setVisitLan(1);
		regBean.setDeviceId(TestDataManager.getRandomUUID().toString());
		regCall.setData(false, regBean);
		regCall.callService();
		if (regCall.getUserid() == 0) {
			return null;
		}
		Map user = new HashMap<String, Object>();
		user.put("phone", phone);
		user.put("loginId", loginId);
		user.put("email", email);
		user.put("userId", regCall.getUserid());
		user.put("token", regCall.getAccessToken());
		user.put("ip", ip);
		user.put("did", regBean.getDeviceId());
		AccountCallService acc = new AccountCallService();
		String accountinfoid = acc.getAccountId(regCall.getUserid());
		if (accountinfoid != null && accountinfoid.length() > 0)
			new AccountCallService().resetAccount(accountinfoid,
					new BigDecimal(1000), new BigDecimal(1000));
		return user;
	}
	/**
	 * 随机生成手机号，发短信
	 * 
	 * @return
	 */
	public static void sendRegisterValidateCode(String Phone) {
		SendRegisterValidateCodeBean srvcbean = new SendRegisterValidateCodeBean();
		SendRegisterValidateCodeCall srvccall = new SendRegisterValidateCodeCall();
		try {
			srvcbean.setPhone(Phone);
			srvccall.setData(false, srvcbean);
			srvccall.callService();
			Logger.debug(srvccall.getEntityString());
			Logger.debug(srvccall.getReturnData());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	/**
	 * 随机生成手机号注册账户, 密码登录默认123456
	 * 
	 * @param phone
	 *            手机号
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public static Map<String, Comparable> registerByMobile(String phone) {
		if (phone == null) {
			phone = TestDataManager.getPhoneNum();
		}
		Map<String, Comparable> userMap = new HashMap<String, Comparable>();
		RegisterByMobileBean rgbmbean = new RegisterByMobileBean();
		RegisterByMobileCall rgbmcall = new RegisterByMobileCall();
		try {
			sendRegisterValidateCode(phone);// 发送验证码
			// 查询验证码
			String code = new YmtValidationCodeWapper().getValidateCode(phone);
			Logger.debug(code);
			rgbmbean.setCode(code);
			rgbmbean.setPhone(phone);
			String userName = "test" + TestDataManager.randomStr(5)
					+ RandomUtils.nextInt(5);
			rgbmbean.setUserName(userName);
			rgbmbean.setPassword("123456a");
			rgbmbean.setUserLogo("userlogo");
			rgbmcall.setData(false, rgbmbean);
			rgbmcall.callService();
			Logger.debug("通过手机注册用户 call:" + rgbmcall.getEntityString());
			Logger.debug("通过手机注册用户 response:" + rgbmcall.getReturnData());
			userMap.put("username", userName);
			userMap.put("phone", phone);
			userMap.put("accesstoken", rgbmcall.getAccessToken());
			userMap.put("userid", rgbmcall.getUserId());
			// 强制更新交易密码为 abc123
			new YmtUsersWapper().updateTradingPwdByUid(rgbmcall.getUserId());
			// 建立用户账户信息 新资金系统上线后，无效
			// getUserAccountInfo(rgbmcall.getUserId());
			// 初始账号可用余额为100W
			// new DefaultWapper().updateAccountInfo(new BigDecimal(1000000),
			// rgbmcall.getUserId());
		} catch (Exception e) {
			Logger.fail(e);
		}
		return userMap;
	}

	/**
	 * 创建微信账号
	 * 
	 * @throws IOException
	 * @throws ClientProtocolException
	 */
	public static Map regByWeiXin(String unionId, String phone,
			Boolean isSuccess, String msg) throws ClientProtocolException,
			IOException {
		if (phone == null) {
			phone = TestDataManager.getPhoneNum();
		}
		WeiXinUserRequestDtoBean regBean = new WeiXinUserRequestDtoBean();
		WeiXinUserRequestDtoCall regCall = new WeiXinUserRequestDtoCall();
		String loginId = "LoginWXUser_" + TestDataManager.getRandomNum(6);
		String openId = "RegopenId_" + TestDataManager.getRandomNum(10);
		regBean.setCountry("China");
		regBean.setProvince("Shanghai");
		regBean.setCity("Shanghai");
		regBean.setClientIp("1.1.1.1");
		regBean.setHeadimgurl("");
		regBean.setName(loginId);
		regBean.setOId(openId);
		regBean.setRegSource("mainsite");
		regBean.setSex("Femail");
		regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
		regBean.setTimeOut(new Date().getTime());
		regBean.setTSource("ios");
		if (phone != null) {
			regBean.setMobile(phone);
		}
		regBean.setUnionId(unionId);
		regBean.setWeixinToken("weixintoken_"
				+ TestDataManager.getRandomNum(10));

		regCall.setData(true, regBean);
		regCall.callService();

		Map<String, Object> user = new HashMap<String, Object>();
		if (isSuccess != null) {
			if (isSuccess) {
				if (msg != null) {
					if (regCall.getString("SuccessMessage") != null) {
						Logger.verifyEquals(msg,
								regCall.getString("SuccessMessage"),
								"验证返回的Message信息");
					} else if (regCall.getString("LastErrorMessage") != null) {
						Logger.verifyEquals(msg,
								regCall.getString("LastErrorMessage"),
								"验证返回的Message信息");
					}
				}
				user.put("userId", regCall.getResult().get("UserId"));
				user.put("loginId", loginId);
				user.put("thirdPartyId", unionId);
				user.put("openId", openId);
			} else {
				if (msg != null) {
					Logger.verifyEquals(msg,
							regCall.getString("LastErrorMessage"),
							"验证返回的Message信息");
				}
			}
		}
		return user;
	}

	/**
	 * 创建微博账号
	 * 
	 * @return
	 * @throws IOException
	 * @throws ClientProtocolException
	 */
	public static Map regByWeibo(String weiboUserId, String phone,
			Boolean isSuccess, String msg) throws ClientProtocolException,
			IOException {
		if (phone == null) {
			phone = TestDataManager.getPhoneNum();
		}
		SinaWeiBoUserRequestDtoBean regBean = new SinaWeiBoUserRequestDtoBean();
		SinaWeiBoUserRequestDtoCall regCall = new SinaWeiBoUserRequestDtoCall();
		String sName = "weibonick_" + TestDataManager.getRandomNum(10);
		regBean.setSWeiboUserId(weiboUserId);
		regBean.setSName(sName);
		regBean.setSMail(TestDataManager.getEmail());
		regBean.setSMobile(TestDataManager.getPhoneNum());
		if (phone != null) {
			regBean.setMobile(phone);
		}
		regBean.setClientIp("120.1.1.1");
		regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
		regBean.setDAddTime(YMTDateUtil.getBeforeOrNextDay(-1));
		regBean.setTerminalSource("ios");
		regBean.setRegSource(1);
		regCall.setData(false, regBean);
		regCall.callService();

		Map<String, Object> user = new HashMap<String, Object>();
		if (isSuccess != null) {
			if (isSuccess) {
				Logger.verifyEquals(msg, regCall.getString("SuccessMessage"),
						"验证返回的Message信息");
				user.put("userId", regCall.getResult().get("UserId"));
				user.put("loginId", sName);
				user.put("thirdPartyId", weiboUserId);
			} else {
				Logger.verifyEquals(msg, regCall.getString("LastErrorMessage"),
						"验证返回的Message信息");
			}
		}
		return user;
	}

	/**
	 * 创建阿里账号
	 * 
	 * @return
	 * @throws IOException
	 * @throws ClientProtocolException
	 */
	public static Map regByAli(String aliUserId, String phone,
			Boolean isSuccess, String msg) throws ClientProtocolException,
			IOException {
		if (phone == null) {
			phone = TestDataManager.getPhoneNum();
		}
		AliUserRequestDtoBean aliuserregbean = new AliUserRequestDtoBean();
		AliUserRequestDtoCall aliuserregCall = new AliUserRequestDtoCall();
		aliuserregbean.setSAliUserId(aliUserId);
		aliuserregbean.setSRealName(aliUserId);
		aliuserregbean.setSEmail(TestDataManager.getEmail());
		aliuserregbean.setRegSource(1);
		aliuserregbean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
		aliuserregbean.setTerminalSource("android");
		aliuserregbean.setClientIp("120.1.1.1");
		aliuserregbean.setTokenTimeOut((new Date()).getTime());
		if (phone != null) {
			aliuserregbean.setMobile(phone);
		}
		aliuserregCall.setData(false, aliuserregbean);
		aliuserregCall.callService();

		Map<String, Object> user = new HashMap<String, Object>();
		if (isSuccess != null) {
			if (isSuccess) {
				Logger.verifyEquals(msg,
						aliuserregCall.getString("SuccessMessage"),
						"验证返回的Message信息");
				user.put("userId", aliuserregCall.getResult().get("UserId"));
				user.put("loginId", aliUserId);
				user.put("thirdPartyId", aliUserId);
				user.put("token", aliuserregCall.getResult().get("Token"));
			} else {
				Logger.verifyEquals(msg,
						aliuserregCall.getString("LastErrorMessage"),
						"验证返回的Message信息");
			}
		}
		return user;
	}

	/**
	 * 绑定手机号
	 * 
	 * @param userId
	 *            用户Id
	 * @param loginId
	 *            登陆Id
	 * @throws IOException
	 * @throws ClientProtocolException
	 */
	public static void bindPhone(int userId, String loginId, String pwd)
			throws ClientProtocolException, IOException {
		LoginBillsRequestDtoBean bindPhoneBean = new LoginBillsRequestDtoBean();
		LoginBillsRequestDtoCall bindPhoneCall = new LoginBillsRequestDtoCall();
		bindPhoneBean.setAction("BindMobile");
		bindPhoneBean.setActionSource("1");
		bindPhoneBean.setLoginPassword(pwd);
		bindPhoneBean.setMobile(TestDataManager.getPhoneNum());
		bindPhoneBean.setUserId(userId);
		bindPhoneBean.setLoginId(loginId);
		bindPhoneCall.setData(false, bindPhoneBean);
		bindPhoneCall.callService();
		Logger.verifyEquals(ECode.SUCCESS,
				bindPhoneCall.getString("ResponseCode"), "验证Code");
		Logger.verifyEquals("true", bindPhoneCall.getString("Success"),
				"验证Success");
		Logger.verifyEquals("Success", bindPhoneCall.getString("Result"),
				"验证凭据");
	}

	/**
	 * 修改用户loginid
	 * 
	 * @param userId
	 * @param loginId
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void modifyLoginId(int userId, String loginId)
			throws ClientProtocolException, IOException {
		Logger.comment("修改userid:" + userId + "的loginId为" + loginId);
		LoginBillsRequestDtoBean bindPhoneBean = new LoginBillsRequestDtoBean();
		LoginBillsRequestDtoCall bindPhoneCall = new LoginBillsRequestDtoCall();
		bindPhoneBean.setAction("ModifyLoginId");
		bindPhoneBean.setUserId(Integer.valueOf(userId));
		bindPhoneBean.setLoginId(loginId);
		bindPhoneBean.setActionSource("0");
		bindPhoneCall.setData(false, bindPhoneBean);
		bindPhoneCall.callService();
	}

	/**
	 * 绑定邮箱
	 * 
	 * @param userId
	 *            用户Id
	 * @param loginId
	 *            登陆Id
	 * @throws IOException
	 * @throws ClientProtocolException
	 */
	public static void bindEmail(int userId, String loginId, String pwd)
			throws ClientProtocolException, IOException {
		LoginBillsRequestDtoBean bindEmailBean = new LoginBillsRequestDtoBean();
		LoginBillsRequestDtoCall bindEmailCall = new LoginBillsRequestDtoCall();
		bindEmailBean.setAction("BindLoginMail");
		bindEmailBean.setActionSource("1");
		bindEmailBean.setLoginId(loginId);
		bindEmailBean.setLoginPassword(pwd);
		bindEmailBean.setMail(TestDataManager.getEmail());
		bindEmailBean.setUserId(userId);
		bindEmailCall.setData(false, bindEmailBean);
		bindEmailCall.callService();
		Logger.verifyEquals(ECode.SUCCESS,
				bindEmailCall.getString("ResponseCode"), "验证Code");
		Logger.verifyEquals("true", bindEmailCall.getString("Success"),
				"验证Success");
		Logger.verifyEquals("Success", bindEmailCall.getString("Result"),
				"验证凭据");
	}

	/**
	 * 检查第三方账号是否需要绑定手机
	 * 
	 * @param thirdPartyId
	 * @param thirdPartyType
	 * @param isNeedBindMobile
	 * @throws ClientProtocolException
	 * @throws IOException
	 * @throws InterruptedException 
	 */
	public static void checkThirdPartyNeedBindMobile(String thirdPartyId,
			String thirdPartyType, String isNeedBindMobile)
			throws ClientProtocolException, IOException, InterruptedException {
		//		Thread.sleep(1000);
		//		CheckThirdPartyUserIsNeedBindMobileDtoBean checkthirdpartyuserisneedbindmobiledtoBean = new CheckThirdPartyUserIsNeedBindMobileDtoBean();
		//		CheckThirdPartyUserIsNeedBindMobileDtoCall checkthirdpartyuserisneedbindmobiledtoCall = new CheckThirdPartyUserIsNeedBindMobileDtoCall();
		//		checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyId(thirdPartyId);
		//		checkthirdpartyuserisneedbindmobiledtoBean.setThirdPartyType(thirdPartyType);
		//		checkthirdpartyuserisneedbindmobiledtoCall.setData(false,checkthirdpartyuserisneedbindmobiledtoBean);
		//		checkthirdpartyuserisneedbindmobiledtoCall.callService();
		//		if (isNeedBindMobile != null) {
		//			Logger.verifyEquals(isNeedBindMobile, checkthirdpartyuserisneedbindmobiledtoCall.getString("Result"), "验证是否需要绑定手机");
		//		}
	}

	/**
	 * 检查手机号是否绑定过第三方账号
	 * 
	 * @param phone
	 * @param thirdPartyId
	 * @param thirdPartyType
	 * @throws IOException
	 * @throws ClientProtocolException
	 * @throws InterruptedException 
	 */
	public static void checkMobileIsBindThirdParty(String phone,
			String thirdPartyId, String thirdPartyType, String result)
			throws ClientProtocolException, IOException, InterruptedException {
		Thread.sleep(2000);
		CheckMobileIsBindThirdPartyUserDtoBean checkmobileisbindthirdpartyuserdtoBean = new CheckMobileIsBindThirdPartyUserDtoBean();
		CheckMobileIsBindThirdPartyUserDtoCall checkmobileisbindthirdpartyuserdtoCall = new CheckMobileIsBindThirdPartyUserDtoCall();
		checkmobileisbindthirdpartyuserdtoBean.setMobile(phone);
		checkmobileisbindthirdpartyuserdtoBean.setThirdPartyId(thirdPartyId);
		checkmobileisbindthirdpartyuserdtoBean
				.setThirdPartyType(thirdPartyType);
		checkmobileisbindthirdpartyuserdtoCall.setData(false,
				checkmobileisbindthirdpartyuserdtoBean);
		checkmobileisbindthirdpartyuserdtoCall.callService();
		Logger.verifyEquals(result,
				checkmobileisbindthirdpartyuserdtoCall.getString("Result"),
				"验证该手机号是否绑定过第三方账号");
	}

	/**
	 * 验证手机号是否绑定过码头账号
	 * 
	 * @param mobile
	 * @throws IOException
	 * @throws ClientProtocolException
	 */
	public static void checkMobileIsBindYmtUser(String mobile, String isBindYmt)
			throws ClientProtocolException, IOException {
		CheckMobileIsBindYmatouUserDtoBean checkmobileisbindymatouuserdtoBean = new CheckMobileIsBindYmatouUserDtoBean();
		CheckMobileIsBindYmatouUserDtoCall checkmobileisbindymatouuserdtoCall = new CheckMobileIsBindYmatouUserDtoCall();
		checkmobileisbindymatouuserdtoBean.setMobile(mobile);
		checkmobileisbindymatouuserdtoCall.setData(false,
				checkmobileisbindymatouuserdtoBean);
		checkmobileisbindymatouuserdtoCall.callService();
		Logger.verifyEquals(isBindYmt,
				checkmobileisbindymatouuserdtoCall.getString("Result"),
				"验证该手机号是否绑定过码头账号");
	}

	/**
	 * 验证绑定了码头账号的第三方账号
	 * 
	 * @param userId
	 * @param thirdParty
	 *            绑定了码头的第三方账号
	 * @throws IOException
	 * @throws ClientProtocolException
	 * @throws InterruptedException 
	 */
	//java改造后不存在解绑 解绑的都删除了
	public static void checkThirdPartyBindYmt(int userId, List<Map> thirdParty)
			throws ClientProtocolException, IOException, InterruptedException {
		//		Thread.sleep(3000);
		//		GetUserThirdPartyAccountDtoBean getuserthirdpartyaccountdtoBean = new GetUserThirdPartyAccountDtoBean();
		//		GetUserThirdPartyAccountDtoCall getuserthirdpartyaccountdtoCall = new GetUserThirdPartyAccountDtoCall();
		//		getuserthirdpartyaccountdtoBean.setUserId(userId);
		//		getuserthirdpartyaccountdtoCall.setData(false,getuserthirdpartyaccountdtoBean);
		//		getuserthirdpartyaccountdtoCall.callService();
		//		Logger.verifyEquals(thirdParty.size(), getuserthirdpartyaccountdtoCall.getResult().size(), "验证返回的数据条数");
		//		for (int i = 0; i < thirdParty.size(); i++) {
		//			boolean flag = false;
		//			Map actual = getuserthirdpartyaccountdtoCall.getResult().get(i);
		//			for (int j = 0; j < thirdParty.size(); j++) {
		//				Map expected = thirdParty.get(j);
		//				if (expected.get("ThirdPartyId").toString().equals(actual.get("ThirdPartyId").toString())) {
		//					Logger.verifyEquals(expected.get("IsBind"), actual.get("IsBind"), "验证是否绑定");
		//					Logger.verifyEquals(expected.get("ThirdPartyType"), actual.get("ThirdPartyType"), "验证第三方类型");
		//					flag = true;
		//				}
		//			}
		//			if (!flag) {
		//				Logger.fail(new Exception("第三方" + actual + "-与实际绑定情况不符"));
		//			}
		//		}
	}

	/**
	 * 添加需要验证的第三方账号
	 * 
	 * @param thirdPartyType
	 * @param thirdPartyId
	 * @param isBind
	 */
	public static void addThirdPartyAccount(List<Map> thirdParty,
			String thirdPartyType, String thirdPartyId, boolean isBind) {
		Map thirdTypeAccount = new HashMap<String, Object>();
		thirdTypeAccount.put("ThirdPartyType", thirdPartyType);
		thirdTypeAccount.put("ThirdPartyId", thirdPartyId);
		thirdTypeAccount.put("IsBind", isBind);
		thirdParty.add(thirdTypeAccount);
	}

	/**
	 * 解绑第三方账号
	 * 
	 * @param userId
	 * @param thirdPartyId
	 * @param thirdPartyType
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static Map unbindThirdParty(int userId, String thirdPartyId,
			String thirdPartyType) throws ClientProtocolException, IOException {
		UnBindThirdPartyAccountDtoBean unbindthirdpartyaccountdtoBean = new UnBindThirdPartyAccountDtoBean();
		UnBindThirdPartyAccountDtoCall unbindthirdpartyaccountdtoCall = new UnBindThirdPartyAccountDtoCall();
		unbindthirdpartyaccountdtoBean.setUserId(userId);
		unbindthirdpartyaccountdtoBean.setThirdPartyId(thirdPartyId);
		unbindthirdpartyaccountdtoBean.setThirdPartyType(thirdPartyType);
		unbindthirdpartyaccountdtoCall.setData(false,
				unbindthirdpartyaccountdtoBean);
		unbindthirdpartyaccountdtoCall.callService();
		return unbindthirdpartyaccountdtoCall.getMap();
	}

	/**
	 * 设置登陆信息
	 * 
	 * @param userId
	 * @param email
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void setLoginBills(int userId, String email)
			throws ClientProtocolException, IOException {
		SetThirdPartyUserLoginBillsDtoBean setthirdpartyuserloginbillsdtoBean = new SetThirdPartyUserLoginBillsDtoBean();
		SetThirdPartyUserLoginBillsDtoCall setthirdpartyuserloginbillsdtoCall = new SetThirdPartyUserLoginBillsDtoCall();
		setthirdpartyuserloginbillsdtoBean.setUserId(userId);
		setthirdpartyuserloginbillsdtoBean.setLoginEmail(email);
		setthirdpartyuserloginbillsdtoBean.setLoginPassword("123456a");
		setthirdpartyuserloginbillsdtoCall.setData(false,
				setthirdpartyuserloginbillsdtoBean);
		setthirdpartyuserloginbillsdtoCall.callService();

		Logger.verifyEquals(ECode.SUCCESS,
				setthirdpartyuserloginbillsdtoCall.getString("ResponseCode"),
				"验证Code");
		Logger.verifyEquals("true",
				setthirdpartyuserloginbillsdtoCall.getString("Success"),
				"验证操作是否成功");
		Logger.verifyEquals("ok",
				setthirdpartyuserloginbillsdtoCall.getString("Result"),
				"验证结果信息");
	}

	/**
	 * 查询用户查询信息接口
	 * 
	 * @param userId
	 *            用户id
	 */
	public static void getUserAccountInfo(int userId) {
		GetUserAccountInfoBean useraccountinfobean = new GetUserAccountInfoBean();
		GetUserAccountInfoCall useraccountinfocall = new GetUserAccountInfoCall();
		try {
			useraccountinfobean.setBuyerId(userId);
			// 发送请求
			useraccountinfocall.setData(false, useraccountinfobean);
			useraccountinfocall.callService();
			Logger.debug("查询用户账号信息 call:"
					+ useraccountinfocall.getEntityString());
			Logger.debug("查询用户账号信息 response:"
					+ useraccountinfocall.getReturnData());
		} catch (Exception e) {
			Logger.fail(e);
		}

	}

	/**
	 * 设置买手在线状态
	 * @param userId
	 * @param optype
	 * @param op
	 */
	public static void setOnlineStatusOp(int userId, String optype, String op) {
		Logger.comment("设置设置买手在线状态userid:" + userId + "optype:" + optype
				+ "op:" + op);
		OnlinestatusOpBean onlinestatusopBean = new OnlinestatusOpBean();
		OnlinestatusOpCall onlinestatusopCall = new OnlinestatusOpCall();
		try {
			onlinestatusopBean.setOpType(optype);
			onlinestatusopBean.setOp(op);
			onlinestatusopBean.setUserId(userId);
			onlinestatusopBean.setOpTime(YMTDateUtil.getSysTime());
			onlinestatusopCall.setData(false, onlinestatusopBean);
			onlinestatusopCall.callService();
		} catch (Exception e) {
			Logger.fail(e);
		}

	}
	/**
	 * 设置买手在线状态
	 * @param userId
	 * @param optype
	 * @param op
	 */
	public static void setOnlineStatusOp(int userId, String optype, String op,
			String optime) {
		Logger.comment("设置设置买手在线状态userid:" + userId + "optype:" + optype
				+ "op:" + op + "optime:" + optime);
		OnlinestatusOpBean onlinestatusopBean = new OnlinestatusOpBean();
		OnlinestatusOpCall onlinestatusopCall = new OnlinestatusOpCall();
		try {
			onlinestatusopBean.setOpType(optype);
			onlinestatusopBean.setOp(op);
			onlinestatusopBean.setUserId(userId);
			onlinestatusopBean.setOpTime(optime);
			onlinestatusopCall.setData(false, onlinestatusopBean);
			onlinestatusopCall.callService();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	/**
	 * 重置登入密码
	 * @param userId
	 * @param newpwd
	 */
	public static void resetLoginPassword(int userId, String newpwd) {
		Logger.comment("设置登入密码userid:" + userId + "：密码:" + newpwd);
		PasswordResetRequestDtoBean passwordresetrequestdtoBean = new PasswordResetRequestDtoBean();
		PasswordResetRequestDtoCall passwordresetrequestdtoCall = new PasswordResetRequestDtoCall();
		try {
			passwordresetrequestdtoBean.setUserId(String.valueOf(userId));
			passwordresetrequestdtoBean.setNewPassword(newpwd);

			passwordresetrequestdtoCall.setData(false,
					passwordresetrequestdtoBean);
			passwordresetrequestdtoCall.callService();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	/**
	 * 修改支付密码
	 * @param userId
	 * @param newpwd
	 */
	public static void modifyTradingPassword(int userId, String newpwd) {
		Logger.comment("设置支付密码userid:" + userId + "：密码:" + newpwd);
		PasswordRequestDtoBean lab = new PasswordRequestDtoBean();
		PasswordRequestDtoCall lac = new PasswordRequestDtoCall();
		try {
			lab.setAType("ByUserId");
			lab.setPasActionType("ModifyTradingPassword");
			lab.setUserId(String.valueOf(userId));
			lab.setNewPassword(newpwd);
			lac.setData(false, lab);
			lac.callService();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	/**
	 * 设置昵称(登入id)，只能修改一次
	 * @param UserId
	 * @param NickName
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void resetNickName(int UserId, String NickName)
			throws ClientProtocolException, IOException {
		Logger.comment("设置昵称uid:" + UserId + "：昵称:" + NickName);
		SetNickNameDtoBean setnicknamedtoBean = new SetNickNameDtoBean();
		SetNickNameDtoCall setnicknamedtoCall = new SetNickNameDtoCall();
		setnicknamedtoBean.setNickName(NickName);
		setnicknamedtoBean.setUserId(UserId);
		setnicknamedtoCall.setData(false, setnicknamedtoBean);
		setnicknamedtoCall.callService();
	}
	/**
	 * 添加头像
	 * @param userid
	 * @param logoUrl
	 * @return
	 * @throws Exception
	 */
	public static UserLogoRequestDtoCall addLogoToUser(int userid,
			String logoUrl) throws Exception {
		Logger.comment("添加头像信息");
		UserLogoRequestDtoBean lbb = new UserLogoRequestDtoBean();
		UserLogoRequestDtoCall lbc = new UserLogoRequestDtoCall();
		lbb = new UserLogoRequestDtoBean();
		lbc = new UserLogoRequestDtoCall();
		lbb.setIUserId(Integer.valueOf(userid));
		lbb.setLogoOperatingAction("Add");
		lbb.setIAction("Default");
		lbb.setSLogoUrl(logoUrl);
		lbc.setData(false, lbb);
		lbc.callService();
		return lbc;
	}
	public static void main(String args[]) {
		UserCallService ucs = new UserCallService();
		ucs.modifyTradingPassword(4085, "abc123");
	}
}
